

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.tdaniel.ws2;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

/**
 *
 * @author Mikey
 */
public class Mailer {

    public void sendConfirmation (String message) throws MessagingException {
        Properties properties = new Properties();
        properties.put("mail.smtp.host", "smtp.gmail.com");
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable","true");
        properties.put("mail.smtp.port", "587");
        Authenticator auth = new MailerAuthenticator();
        Session session = Session.getDefaultInstance(properties, auth);
        Message msg = new MimeMessage(session);
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress("workshop2222@gmail.com"));
        msg.setSubject("Confirmation of your transaction");
        msg.setContent(message, "text/plain");
        Transport.send(msg);
}
    
    private class MailerAuthenticator extends javax.mail.Authenticator
    {
        @Override
        public PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication("workshop2222@gmail.com", "basicwebapplication");
        }
    }
} 